package com.gsoe.judge.listen;

import com.gsoe.base.exception.JudgeException;
import com.gsoe.base.model.MqMessage;
import com.gsoe.dto.JudgeExamDTO;
import com.gsoe.dto.SaveJudgeTestDTO;
import com.gsoe.judge.service.JudgeExamService;
import com.gsoe.judge.service.JudgeTestService;
import com.gsoe.po.JudgeExam;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MqListen {
    @Autowired
    JudgeTestService judgeTestService;
    @Autowired
    JudgeExamService judgeExamService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "saveJudgeTest.queue1"),
            exchange=@Exchange(name="judge.direct",type = ExchangeTypes.DIRECT),
            key={"saveJudgeTest"}
    ))
    public void saveJudgeTest(SaveJudgeTestDTO saveJudgeTestDTO) {
        judgeTestService.saveJudgeTest(saveJudgeTestDTO);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name="saveJudgeExam.queue1"),
            exchange=@Exchange(name="judge.direct",type = ExchangeTypes.DIRECT),
            key={"saveJudgeExam"}
    ))
    public void saveJudgeExam(List<JudgeExamDTO> judgeExamDTO) {
        judgeExamService.saveJudgeExam(judgeExamDTO);
    }
}
